import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { MailerModule } from '@nestjs-modules/mailer';
import { EjsAdapter } from '@nestjs-modules/mailer/dist/adapters/ejs.adapter';
import * as config from 'config';
import { IoredisModule } from '../ioredis/ioredis.module';
import { JwtModule } from '@nestjs/jwt';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '../user/entities/user.entity';
import { RoleModule } from '../role/role.module';

@Module({
  imports: [
    IoredisModule,
    RoleModule,
    TypeOrmModule.forFeature([User]),
    MailerModule.forRoot({
      transport: {
        host: config.get('mail.host'),
        port: config.get('mail.port'),
        secure: config.get('mail.secure'),
        auth: {
          user: config.get('mail.username'),
          pass: config.get('mail.password')
        }
      },
      // preview: true,
      defaults: {
        from: config.get('mail.username')
      },
      template: {
        dir: process.cwd() + '/src/common/templates',
        adapter: new EjsAdapter(),
        options: {
          strict: true // 严格模式
        }
      }
    }),
    JwtModule.registerAsync({
      useFactory: () => {
        return {
          secret: config.get('jwt.secret'),
          signOptions: {}
        };
      }
    })
  ],
  controllers: [AuthController],
  providers: [AuthService],
  exports: [AuthService]
})
export class AuthModule {}
